<div class="weadmin-body layui-main">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="we-red">*</span>用户名
            </label>
            <div class="layui-input-block">
                <input type="text" placeholder="请输入名称" name="username" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label for="note" class="layui-form-label">所属角色</label>
            <div class="layui-input-block">
                <select name="role_id" class="layui-select">
                    <option value="">请选择</option>
                <?php foreach ($role_list as $role):?>
                    <option value="<?php echo $role->id?>"><?php echo $role->name?></option>
                <?php endforeach;?>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="create" lay-submit="">添加</button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'jquery', 'layer'], function() {
        var form = layui.form,
            $ = layui.jquery,
            layer = layui.layer;
        //监听提交
        form.on('submit(create)', function(data) {
            $.post('<?php $this->createUrl('admin/create')?>', data.field,function (ret) {
                if (ret.code == 0) {
                    layer.alert(ret.message, function (index) {
                        layer.close(index);
                        if (window == window.top) {
                            $('form')[0].reset();
                        } else {
                            var index = window.parent.layer.getFrameIndex(window.name);
                            window.parent.layer.close(index);
                            window.parent.location.reload();//刷新父界面
                        }
                    });
                } else {
                    layer.alert(ret.message);
                }
            });
            return false;
        });
    });
</script>
